package c1761;

import java.util.Scanner;
import java.util.TreeSet;

public class F2 {
    static Scanner cin = new Scanner(System.in);
    public static void main(String[] args) {
        int T = cin.nextInt();
        while (T-- > 0) {
            int n = cin.nextInt();
           TreeSet<Rectangle> rects=new TreeSet<>();
            for (int i = 0; i < n; i++) {
                Rectangle rect= new Rectangle(cin.nextInt(), cin.nextInt(),
                        cin.nextInt());
                rects.add(rect);
            }
           for(Rectangle rect:rects){
               System.out.println(rect);
           }
        }
        cin.close();
    }

    static class Rectangle implements Comparable<Rectangle> {
        int len, wid, num;// len>=wid

        public Rectangle(int num, int len, int wid) {
            super();
            this.len = Math.max(len, wid);
            this.wid = Math.min(len, wid);
            this.num = num;
        }

        @Override
        public String toString() {
            return String.format("%d %d %d", num, len, wid);
        }

        @Override
        public int compareTo(Rectangle that) {
            if (this.num != that.num)
                return this.num - that.num;// order by num asc
            if (this.len != that.len)
                return this.len - that.len;

            return this.wid - that.wid;
        }

    }

}
